home *** CD-ROM | disk | FTP | other *** search
- Path: xylogics.com!not-for-mail
- From: carlson@xylogics.com (James Carlson)
- Newsgroups: comp.std.c
- Subject: Re: Q: char **foo, char *foo[], and char foo[][] ?
- Date: 19 Apr 1996 08:20:11 -0400
- Organization: Xylogics Incorporated
- Distribution: world
- Message-ID: <4l80dr$q6@newhub.xylogics.com>
- References: <4l33ok$oo2@Sherlock.lectra.fr> <KANZE.96Apr18105949@gabi.gabi-soft.fr>
- Reply-To: carlson@xylogics.com
- NNTP-Posting-Host: newhub.xylogics.com
-
-
- In article <KANZE.96Apr18105949@gabi.gabi-soft.fr>, kanze@gabi-soft.fr (J. Kanze) writes:
- |> In article <4l33ok$oo2@Sherlock.lectra.fr> phil@rd.lectra.fr (Philippe
- |> Maurisset) writes:
- [...]
- |>
- |> |> myexample()
- |> |> {
- |> |> char foo[MAX_X][MAX_Y];
- |> |> ...
- |> |> myfunc( (char **)foo );
- |> |> }
- |>
- |> |> void myfunc( char *foo[MAX_X] )
- |> ^^^^^^^^^^^^^^^^
- |>
- |> Because it appears as a function parameter, this is actually a
- |> declaration of a char**, and not a char*[].
-
- True.
-
- |> So in fact, you have no type incompatibility to deal with.
-
- Not true. The original definition of foo in myexample() was as a two-
- dimensional array, which, in C, is implemented in storage as a
- unidimensional array of size MAX_X*MAX_Y*sizeof(char), not as an array
- of pointers-to-characters. If you try to access this as a pointer-to-a-
- pointer, you will be attempting to dereference character data as a
- pointer. (If you've got a real operating system, then this just results
- in a core fault. If you're running on a toy, the results could be far
- worse.)
-
- (Of course, the type of the formal argument is compatible with the
- cast given in the call, but the cast itself is bogus.)
-
- --
- James Carlson <carlson@xylogics.com> Tel: +1 617 272 8140
- Annex Interface Development / Xylogics, Inc. +1 800 225 3317
- 53 Third Avenue / Burlington MA 01803-4491 Fax: +1 617 272 2618
-